<template>
  <div>
    <form action="/" class="search">
      <van-search
        v-model="value"
        show-action
        :autofocus="true"
        placeholder="输入影城名称"
        @search="onSearch"
        @cancel="onCancel"
      />
    </form>

    <div class="close-cinemas" v-show="!value">
      <div class="cinema-name">离你最近</div>
      <div class="top-cinema">
        <div v-for="item in topList" :key="item.id" @click="">
          <div class="name">{{ item.name }}</div>
        </div>
      </div>
    </div>

    <ul v-show="value">
      <li v-for="item in computedList" :key="item.cinemaId">
        <div class="left">
          <div class="name">{{ item.name }}</div>
          <div class="address">{{ item.address }}</div>
        </div>
        <div class="right">
          <div>￥<span>{{ (item.lowPrice / 100).toFixed(1) }}</span>起</div>
          <div class="distance">{{ (item.Distance * 500).toFixed(2) }}km</div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import {mapState, mapGetters, mapActions} from 'vuex';
import myMixin from "@/util/myMixin";

export default {
  mixins: [myMixin],

  data() {
    return {
      value: '',
    };
  },
  computed: {
    ...mapState(['cinemaList', 'cityId']),
    ...mapGetters(['topList']),

    computedList() {
      return this.cinemaList.filter(item => item.name.toUpperCase().includes(this.value.toUpperCase()) ||
        item.address.toUpperCase().includes(this.value.toUpperCase()))
    },
  },
  methods: {
    ...mapActions(['getCinemaData']),

    onSearch() {

    },
    onCancel() {
      this.value = ''
      this.$router.back()
    },
  },
  created() {
    // dispatch：分发
    // stare里面有cinema数据就不需要发起请求
    if (this.cinemaList.length === 0) {
      this.getCinemaData(this.cityId)
    }

  },

};

</script>
<style lang="scss" scoped>
.search {
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99999;
}

.van-search {
  border-bottom: 1px solid #ebedf0;
}

.van-search--show-action {
  padding-left: 15px;
  height: 50px;
}

.van-field {
  padding: 3px 0;
}

.van-search__content--square {
  background-color: #f4f4f4;
}

.van-search__action {
  padding: 0 15px;
}

.van-search__action:active {
  background-color: #fff;
}

/* 影院布局样式 */
.van-icon-arrow-down {
  display: inline-block;
  font-size: 8px;
  -webkit-transform: scale(0.75); /*针对Chrome 设置字体缩小比例*/
  -o-transform: scale(1); /*针对能识别-webkit的opera browser设置*/
}

.close-cinemas {
  margin-left: 15px;
  padding: 0 15px 8px 0;
  font-size: 13px;
  color: #3b3b3d;
  position: absolute;
  top: 50px;
  left: 0;
  box-sizing: border-box;
  -moz-box-sizing: border-box; /* Firefox */
  -webkit-box-sizing: border-box; /* Safari */

  .cinema-name {
    margin: 18px 0;
    color: #bdc0c5;
  }

  .name {
    font-size: 14px;
    padding: 8px 12px;
    height: 20px;
    line-height: 20px;
    background-color: #f4f4f4;
    margin: 0 10px 10px 0;
    border-radius: 3px;
  }

  .top-cinema {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
  }
}


li {
  height: 45px;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  position: relative;


  .left {
    width: 2.12rem;
    padding-right: 15px;

    .name {
      font-size: 15px;
      color: #191a1b;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .address {
      color: #797d82;
      font-size: 12px;
      margin-top: 5px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  .right {
    font-size: 12px;
    color: #ff5f16;

    span {
      font-size: 15px;
    }

    .distance {
      color: #797d82;
      margin-top: 5px;
    }
  }
}

ul {
  margin-top: 50px;
}

li:before {
  position: absolute;
  right: 0;
  top: 0;
  left: 0;
  height: 1px;
  content: '';
  -webkit-transform: scaleY(.5);
  transform: scaleY(.5);
  border-top: 1px solid #ececec;
}
</style>
